package persistentie;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;


import domein.Continent;

public class ContinentenMapper extends Mapper<Continent>
{
	private static final String querySelectContinenten = "SELECT * FROM continenten";

	public Map<String, Continent> read() throws SQLException, IllegalStateException, ClassNotFoundException
	{
		Connectie connectie = new Connectie();
		Map<String, Continent> map = new HashMap<String, Continent>();
		ResultSet resultSet;
		
		try 
		{
			resultSet = connectie.executeQuery(querySelectContinenten);
			
			while (resultSet.next()) {
				String naamContinent = resultSet.getString("naamContinent");
				String idContinent = Integer.toString(resultSet.getInt("idContinent"));
				Continent continent = new Continent(idContinent, naamContinent);
				map.put(naamContinent, continent);
			}
			
		}
		catch (Exception e) 
		{
			e.printStackTrace();
			System.out.print("error");
		}
		
		connectie.closeConnection();
		
		return map;
	}
	
	
	
}
